#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QString>
#include <QSerialPort>
#include <QtCharts>

namespace Ui {
class Widget;
}


class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

    QSerialPort *serialPort;//定义串口指针

    QTimer *timer;//定时器

    int iGetPowerStep = 0;

    int iSetTestTime = 0;
    int iKeepTestTime = 0;

    float fCH1RealtimeVal = 0;//实时值
    float fCH1MaxVal = 0;//最大值
    float fCH2RealtimeVal = 0;
    float fCH2MaxVal = 0;
    float fCH3RealtimeVal = 0;
    float fCH3MaxVal = 0;

private slots:
    void on_updateSerialBt_clicked();

    void on_openSerialBt_clicked();

    void on_closeSerialBt_clicked();

    void on_clearPortTextBt_clicked();

    void handlePowerData();//处理功率数据

    void on_startTestBt_clicked();

    void sendBySerialPort(const char *sendData);

    void getPowerData();

    void on_stopTestBt_clicked();

private:
    Ui::Widget *ui;

private:

    QLineSeries *ch1PowerSeries;//通道1功率折线

    QLineSeries *ch2PowerSeries;

    QLineSeries *ch3PowerSeries;

    QChart *powerChart;

    QChartView *powerChartView;

    QValueAxis *axisX;         // X轴
    QValueAxis *axisY;         // Y轴


    // 创建图表
    void creatChart();
    //初始化图表
    void initChart();
    //更新图表
    void updateChart();

    //初始化数据
    void initPowerValue();

    //导出数据
    void exportPowerData();

    //求平均值
    void ch1GetAvgPowerVal();
    void ch2GetAvgPowerVal();
    void ch3GetAvgPowerVal();

};

#endif // WIDGET_H
